package com.sunfeng.chap2.p13;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

/**
 * @Author : 孙峰
 * @Description:   首先执行Test13_1 类的实现代码 然后运行Test13_2类实现代码 B begin
 * @Date : 2021/10/9  15:42
 */
public class Test13_2 {
    public static void main(String[] args) throws IOException, InterruptedException {
        RandomAccessFile file = new RandomAccessFile("d:\\nio\\a.txt", "rw");
        FileChannel fileChannel = file.getChannel();

        System.out.println("B begin");
        fileChannel.lock(1, 2, false);
        System.out.println("B end");
        Thread.sleep(Integer.MAX_VALUE);
        file.close();
        fileChannel.close();
    }
}
